Inside Macintosh: Files

Previous | Chapter Top | Chapter Contents | Next

Manipulating the File Mark

You can use the functions GetFPos and SetFPos to get or set the current position of the file mark.

GetFPos

You can use the GetFPos function to determine the current position of the mark before reading from or writing to an open file.

FUNCTION GetFPos (refNum: Integer; VAR filePos: LongInt): OSErr;
refNum
The file reference number of an open file.
filePos
On output, the current position of the mark.

DESCRIPTION

The GetFPos function returns, in the filePos parameter, the current position of the file mark for the specified open file. The position value is zero-based; that is, the value of filePos is 0 if the file mark is positioned at the beginning of the file.

RESULT CODES

noErr

0

No error

ioErr

-36

I/O error

fnOpnErr

-38

File not open

rfNumErr

-51

Bad reference number

gfpErr

-52

Error during GetFPos

SetFPos

You can use the SetFPos function to set the position of the file mark before reading from or writing to an open file.

FUNCTION SetFPos (refNum: Integer; posMode: Integer;
                                         posOff: LongInt): OSErr;
refNum
The file reference number of an open file.
posMode
The positioning mode.
posOff
The positioning offset.

DESCRIPTION

The SetFPos function sets the file mark of the specified file. The posMode parameter indicates how to position the mark; it must contain one of the following values:

CONST
    fsAtMark        = 0;    {at current mark}
    fsFromStart     = 1;    {set mark relative to beginning of file}
    fsFromLEOF      = 2;    {set mark relative to logical end-of-file}
    fsFromMark      = 3;    {set mark relative to current mark}

If you specify fsAtMark , the mark is left wherever it's currently positioned, and the posOff parameter is ignored. The next three constants let you position the mark relative to either the beginning of the file, the logical end-of-file, or the current mark. If you specify one of these three constants, you must also pass in posOff a byte offset (either positive or negative) from the specified point. If you specify fsFromLEOF , the value in posOff must be less than or equal to 0.

RESULT CODES

noErr

0

No error

ioErr

-36

I/O error

fnOpnErr

-38

File not open

eofErr

-39

Logical end-of-file reached

posErr

-40

Attempt to position mark before start of file

rfNumErr

-51

Bad reference number


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next